// Copyright 2009 StarCite Inc.  All rights reserved.
// XmlReader.java 2:03:18 PM danny.liu
package com.billowsoft.performance.xml;

import java.io.File;
import java.io.FileInputStream;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

/**
 * @author danny.liu Mar 23, 2012
 * @version 1.0
 * 
 */
public class XmlReader {
	public static void read() throws Exception {
		XMLInputFactory factory = XMLInputFactory.newInstance();
		XMLStreamReader reader = factory
				.createXMLStreamReader(new FileInputStream(
						new File("input.xml")));
		while (reader.hasNext()) {
			printEventInfo(reader);
		}
		System.out.println(result.toString());
	}

	public static void main(String[] args) throws Exception {
		read();
	}

	private static int previousEvent = 0;
	private static String previousLocalName = "";
	private static StringBuilder result = new StringBuilder();

	private static void printEventInfo(XMLStreamReader reader)
			throws XMLStreamException {
		int eventCode = reader.next();
		System.out.println(eventCode);
		System.out.println(reader.getLocalName());
		try {
			System.out.println(reader.getText());
		} catch (Exception e) {

		}
		System.out.println("===============");
	}
}
